﻿using System;
using System.Collections.Generic;
using System.Text;

public class GameEngine
{
    private const char k_QuitChar = 'q';
    private const int k_MinColumn = 1;
    private readonly BoardService r_BoardService = null;
    private readonly PlayersService r_PlayerService = null;
    private bool IsTwoUserPlayers = false;

    public Cell[,] BoardMatrix
    {
        get { return r_BoardService.BoardMatrix; }
    }

    internal int DiscsCounter
    {
        get { return r_BoardService.DiscsCounter; }
        set { r_BoardService.DiscsCounter = value; }
    }

    public GameEngine(int i_BoardViewRowSize, int i_BoardViewColSize, bool i_IsTwoUserPlayers)
    {
        IsTwoUserPlayers = i_IsTwoUserPlayers;
        r_BoardService = new BoardService(i_BoardViewRowSize, i_BoardViewColSize);
        r_PlayerService = new PlayersService(i_IsTwoUserPlayers);
    }

    public enum eGameMoveStatus
    {
        PlayerWin = 0,
        BoardIsFull,
        ColumnIsFull,
        Quit,
        Continue
    }

    public int NumOfPlayers 
    {
        get { return r_PlayerService.NumOfPlayers; }
    }

    public void UpdateWinnerScore(int i_CurrentPlayerIndex)
    {
        r_PlayerService.UpdateWinnerScore(i_CurrentPlayerIndex);
    }

    public int GetPlayerScore(ePlayerIndex i_PlayerIndex)
    {
        return r_PlayerService.GetPlayerScoreByIndex((int)i_PlayerIndex);
    }

    public enum ePlayerIndex
    {
        FirstPlayer = 0,
        SecondPlayer = 1
    }

    public Player GetPlayerByIndex(int i_CurrentPlayerIndex)
    {
        return r_PlayerService.GetPlayerByIndex(i_CurrentPlayerIndex);
    }

    public int BoardMatrixColSize 
    {
        get { return r_BoardService.BoardMatrixColSize; }
    }

    public void MakeEmptyBoard()
    {
        r_BoardService.MakeEmptyBoard();
    }

    public GameEngine.eGameMoveStatus AddDisc(int i_ChosenColumn, int i_CurrentPlayerIndex)
    {
        return r_BoardService.AddDisc(i_ChosenColumn, i_CurrentPlayerIndex);
    }
}